package content;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class MyDialog extends Dialog {

	protected Object result;
	protected Shell shlX;
	private Text text;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public MyDialog(Shell parent) {
		super(parent);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shlX.open();
		shlX.layout();
		Display display = getParent().getDisplay();
		while (!shlX.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shlX = new Shell(getParent(), getStyle());
		shlX.setSize(350, 216);
		shlX.setText("X");
		
		Button btnNewButton = new Button(shlX, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shlX.close();
				shlX.dispose();
			}
		});
		btnNewButton.setBounds(318, 0, 30, 27);
		btnNewButton.setText("X");
		
		text = new Text(shlX, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
		text.setBounds(10, 32, 328, 172);

	}

}
